<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="x-ua-compatible" content="IE=edge,chrome=1">
    <meta name="renderer" content="webkit">
    <title>新增友链</title>

    <!-- 引入Amaze css -->
    <link rel="stylesheet" href="/assets/amazeui/css/amazeui.min.css"/>

    <link rel="stylesheet" href="/assets/css/admin.css"/>

    <link rel="stylesheet" href="/assets/layer/skin/layer.css"/>
    <link rel="stylesheet" href="/assets/layer/skin/layer.ext.css"/>
</head>
<body>
<form id="link_form" class="am-form">
    <input type="hidden" name="link.id" value="${link.id!}">

    <div class="am-g am-margin-top">
        <div class="am-u-sm-4 am-u-md-2 am-text-right">
            链接名称
        </div>
        <div class="am-u-sm-8 am-u-md-4">
            <input id="link_name" type="text" class="am-input-sm" name="link.link_name" value="${link.link_name!}">
        </div>
        <div class="am-hide-sm-only am-u-md-6">*必填</div>
    </div>

    <div class="am-g am-margin-top">
        <div class="am-u-sm-4 am-u-md-2 am-text-right">
            链接地址
        </div>
        <div class="am-u-sm-8 am-u-md-4 am-u-end col-end">
            <input id="link_link" type="text" class="am-input-sm" name="link.link" value="${link.link!}">
        </div>
        <div class="am-hide-sm-only am-u-md-6">*必填</div>
    </div>

    <!-- 以后再使用 -->
    <!--<div class="am-g am-margin-top">
        <div class="am-u-sm-4 am-u-md-2 am-text-right">
            链接图片
        </div>
        <div class="am-u-sm-8 am-u-md-4 am-u-end col-end">
            <input type="text" class="am-input-sm">
        </div>
        <div class="am-hide-sm-only am-u-md-6">
            <img src="${link.icon!}" alt="link icon">
        </div>
    </div>-->

    <div class="am-g am-margin-top">
        <div class="am-u-sm-4 am-u-md-2 am-text-right">
            显示状态
        </div>
        <div class="am-u-sm-8 am-u-md-4 am-u-end col-end">
            <select id="link_status" name="link.status" data-am-selected="{btnSize: 'sm'}">
                <option value="1">显示</option>
                <option value="0">不显示</option>
            </select>
        </div>
    </div>
    <div class="am-g am-margin-top">
        <div class="am-margin am-center">
            <button id="link_submit" type="button" class="am-btn am-btn-default am-btn-xs">提交</button>
            <button id="link_close" type="button" class="am-btn am-btn-default am-btn-xs">放弃</button>
        </div>
    </div>
</form>

<!-- start script -->
<!--[if lt IE 9]>
<script src="/assets/js/jq/jquery-1.11.3.js"></script>
<script src="http://cdn.staticfile.org/modernizr/2.8.3/modernizr.js"></script>
<script src="/assets/amazeui/js/amazeui.ie8polyfill.min.js"></script>
<![endif]-->

<!--[if (gte IE 9)|!(IE)]><!-->
<script src="/assets/js/jq/jquery-2.1.4.js"></script>
<!--<![endif]-->
<script src="/assets/amazeui/js/amazeui.min.js"></script>
<!-- layer -->
<script src="/assets/layer/layer.js"></script>
<script src="/assets/layer/extend/layer.ext.js"></script>
<!-- date ext -->
<script src="/assets/js/date.ext.js"></script>
<!-- link js -->
<script src="/assets/js/link.js"></script>
<script>
    //check for link form
    function check_link_form() {
        if ($.trim($("#link_name").val()) == '') {
            layer.alert('友链名称不能为空', {icon: 5});
            return false;
        }
        if ($.trim($("#link_link").val()) == '') {
            layer.alert('友链地址不能为空', {icon: 5});
            return false;
        }
        return true;
    }

    $(document).ready(function () {
        var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
        var link_form = $("#link_form");
        //add onclick for link_submit->submit form and close the layer
        $("#link_submit").on('click', function () {
            if (check_link_form()) {
                $.post("/admin/link/put", link_form.serialize(), function (result) {
                    result = $.parseJSON(result);
                    console.log(result);
                    if (result && result.code == 100) {
                        //submit success
                        parent.link.init_link_table();
                        parent.layer.close(index);
                    } else {
                        layer.msg("操作失败,请稍后再试");
                    }
                });
            }
        });

        //add onclick->close the layer
        $("#link_close").on('click', function () {
            parent.layer.close(index);
        });
    });
</script>
</body>
</html>